package helloworld.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class MulticastSender {
	private static final int TTL = 255;

	public MulticastSender() {
		MulticastSocket multicastSocket = null;
		try {
			multicastSocket = new MulticastSocket();
			multicastSocket.setTimeToLive(TTL);
			String message = "Hello,it's multicast!";
			byte[] bytesToSend = message.getBytes();
			DatagramPacket datagramPacket = new DatagramPacket(bytesToSend,
					bytesToSend.length, InetAddress.getByName("224.0.0.0"),
					8089);
			multicastSocket.send(datagramPacket);
			multicastSocket.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}